<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

Route::middleware('auth:sanctum')->post('/reverb/auth', function (Request $request) {
    $socketId = $request->input('socket_id');
    $channelName = $request->input('channel_name');
    if (!$socketId || !$channelName) {
        return response()->json(['error' => 'Missing socket_id or channel_name'], 400);
    }

    $appKey = env('REVERB_APP_KEY');
    $appSecret = env('REVERB_APP_SECRET');

    $auth = hash_hmac('sha256', $socketId . ':' . $channelName, $appSecret);

    return response()->json([
        'auth' => $appKey . ':' . $auth
    ]);
});
